//
//  HealthViewController.m
//  TestDemo
//
//  Created by fengxijun on 3/25/16.
//  Copyright © 2016 goappbox. All rights reserved.
//

#import "HealthViewController.h"
#import <HealthKit/HealthKit.h>

@interface HealthViewController ()
@property (nonatomic, strong) HKHealthStore *healthStore;
@end

@implementation HealthViewController

-(void)viewDidLoad
{
    [super viewDidLoad];
    if ([HKHealthStore isHealthDataAvailable]) {
        self.healthStore = [[HKHealthStore alloc] init];
        HKWorkoutType *workoutType = [HKObjectType workoutType];
        HKQuantityType *quantityType = [HKObjectType quantityTypeForIdentifier:@"com.mainbo.yqj"];
        
        [_healthStore requestAuthorizationToShareTypes:[NSSet setWithObjects:quantityType, nil] readTypes:[NSSet setWithObjects:workoutType,quantityType, nil] completion:^(BOOL success, NSError * _Nullable error) {
            NSLog(@"%@",error);
        }];
        [self testHealthStoreData];
    }
}

- (void) testHealthStoreData
{
    NSError *error = nil;
    NSDate *date = [_healthStore dateOfBirthWithError:&error];
    HKBloodTypeObject *bloodTypeObject = [_healthStore bloodTypeWithError:&error];
    HKBiologicalSexObject *biologicalSexObject = [_healthStore biologicalSexWithError:&error];
    HKFitzpatrickSkinTypeObject *fitzpatrickSkinTypeObject = [_healthStore fitzpatrickSkinTypeWithError:&error];
}

@end
